|
|
|
|
|
|
|
When the application runs, you should see the HTML screen provided by the WebClass's Start event. If you look in the project directory, you might notice that Visual Basic has created an ASP file that creates an instance of your WebClass. By now, you should understand a little bit more about how an IIS application workskind of like an ASP file but with all of the Web activity accessible through the Visual Basic environment. In the next section, you learn more about what a WebClass can do by adding WebItems to it. For now, stop the project in Visual Basic and return to design mode. |
|
|
|
|
|
|
|
|
Open the Code window again and note the standard events available for a WebClass. Put Debug.Print eventname statements in each of them and run the project again. Watch the sequence of events: |
|
|
|
|
|
|
|
|
1. When you start the project, the browser is launched. The ASP file loaded by the browser contains a Server.CreateObject statement, which creates an instance of the WebClass, causing the Initialize event to fire. |
|
|
|
|
|
|
|
|
2. The ASP file also makes a request for a Web page to the WebClass, causing the BeginRequest event to fire. |
|
|
|
|
|
|
|
|
3. The WebClass's Start event fires (much like the Form_Load event) causing HTML to be sent back to the browser. |
|
|
|
|
|
|
|
|
4. When all the HTML has been sent to the browser, the request has been satisfied so the EndRequest event fires. |
|
|
|
|
|
|
|
|
5. The Terminate event fires, causing the instance of the WebClass to be destroyed. |
|
|
|
|
|
|
|
|
Step 5 in the preceding list should have at least caused you to raise an eyebrow. Why was the WebClass created and then immediately destroyed? The answer is because the StateManagement property of the WebClass was set to wcNoState. This means if you set a local variable or property in the Start event of the WebClass, it would not be available on successive calls. If the StateManagement property was set to wcRetainInstance then each call to the WebClass from the ASP page would be to the same instance, and you could store state information. |
|
|
|
|
|
|
|
|
However, there is a deeper issue here than just setting a property. It is more a philosophy of how you write applications. The connection-less nature of the Web is more suited to transaction-based processing instead of state-based processing. When working with transactions, you really don't care about communicating with the same instance of an object because you pass all the information needed to complete a transaction along with each call to the object. |
|
|
|
|
|
|
|
|
Most of us tend to write code that depends on an object's being in a certain statefor example, you will set a bunch of properties on an object and then later call a method on the object that uses those properties: |
|
|
|
|
|
|
|
|
x.AccountID = 123456
x.AccountHolder = "Stephanie and Brent" |
|
|
|
|
|